//
//  LTChatroomManager.m
//  linktuIOS
//
//  Created by 俊松何 on 2017/5/19.
//  Copyright © 2017年 tianxie. All rights reserved.
//

#import "LTChatroomManager.h"
#import "LTHTTPTool.h"
#import "LTLib.h"
@implementation LTChatroomManager


-(void)addDelegate:(id<LTChatroomManagerDelegate>)deleagte
{
    
    [self.chatRoomMangerdelegateArray addObject:deleagte];
    
}

-(void)removeDelegate:(id<LTChatroomManagerDelegate>)delegate
{
    [self.chatRoomMangerdelegateArray removeObject:delegate];
    
}

/**
 加入聊天室
 
 @param roomID 房间ID
 @param completion  加入的回调
 */
-(void)joinChatRoom:(NSString *)roomId
         completion:(void (^)(LTError *lterror))completion
{
    
    NSDictionary *param = @{@"roomId":roomId,@"userId":[LTClient sharedClient].currentUserId};
    [[LTHTTPTool shareTool] postPath:@"/chatRoom/join" parameters:param success:^(LTBaseDataModel *datamodel) {
        completion(nil);
    } parmerror:^(LTBaseDataModel *datamodel) {
        LTError *lterror = [LTError errorWithDescription:datamodel.message code:datamodel.code];
        completion(lterror);
    } failer:^(NSError *error) {
         LTError *lterror = [LTError errorWithDescription:@"网络错误" code:-1];
        completion(lterror);
    }];
    

}


/**
 退出聊天时的回调
 
 @param roomId 房间id
 @param completion 完成的回调
 */
-(void)leaveChatRoom:(NSString *)roomId
          completion:(void (^)(LTError *lterror))completion
{


    NSDictionary *param = @{@"roomId":roomId,@"userId":[LTClient sharedClient].currentUserId};
    
    
    [[LTHTTPTool shareTool] postPath:@"/chatRoom/quit" parameters:param success:^(LTBaseDataModel *datamodel) {
        completion(nil);
    } parmerror:^(LTBaseDataModel *datamodel) {
        LTError *lterror = [LTError errorWithDescription:datamodel.message code:datamodel.code];
        completion(lterror);
    } failer:^(NSError *error) {
        LTError *lterror = [LTError errorWithDescription:@"网络错误" code:-1];
        completion(lterror);
    }];
}


-(NSMutableArray *)chatRoomMangerdelegateArray
{
    if(_chatRoomMangerdelegateArray == nil)
    {
        _chatRoomMangerdelegateArray = [NSMutableArray arrayWithCapacity:1];
    }
    return _chatRoomMangerdelegateArray;
}

@end
